#define BANMSG "You have been banned from [world.name]"
#define BANFILELOC "bans.txt"
client
	New()
		..()
		var/list/banfile = BS_BanList()
		if(banfile.Find(src.ckey)||banfile.Find(src.address))
			del(src)
proc
	BS_Ban(mob/M, mob/T)
		if(M == T)
			return "You can not ban your self."
		if(M.client.address == world.address)
			return "You can not ban the host."
		if(!M)
			return "Error, no user."
		var/list/banfile = new
		banfile += M.ckey
		BS_BanWrite(banfile)
		M << BANMSG
		del(M)
		return "[M], [M.client.address] banned"
	BS_BanIP(mob/M, mob/T)
		if(M.client.address == T.client.address)
			return "You can not ban your self."
		if(M.client.address == world.address)
			return "You can not ban the host."
		if(!M.client.address)
			return "Error, no address."
		var/list/banfile = new
		banfile += M.client.address
		BS_BanWrite(banfile)
		M << BANMSG
		del(M)
		return "[M], [M.client.address] banned"
	BS_BanList()
		var/list/banfile = TF_ReadWrite(BANFILELOC, "Read")
		return banfile
	BS_BanWrite(data)
		TF_ReadWrite(BANFILELOC, data)






























//Uses modified procs from Deadron.TextHandling

proc
	TF_ReadWrite(file_path, data)
		if(data == "Read"||data == "read")
			return TF_file2list(file_path)
		else
			return TF_list2file(data, file_path)
	TF_list2file(data, file_path, separator = "\n")
		var/file
		if (isfile(file_path))
			file = file_path
		else
			file = file(file_path)
		return text2file(TF_list2text(data, separator), file)
	TF_file2list(file_path, separator = "\n")
		var/file
		if (isfile(file_path))
			file = file_path
		else
			file = file(file_path)
		return TF_text2list(file2text(file), separator)
	TF_list2text(list/the_list, separator)
		var/total = the_list.len
		if (total == 0)														// Nothing to work with.
			return

		var/newText = "[the_list[1]]"										// Treats any object/number as text also.
		var/count
		for (count = 2, count <= total, count++)
			if (separator) newText += separator
			newText += "[the_list[count]]"
		return newText
	TF_text2list(text, separator)
		var/textlength      = lentext(text)
		var/separatorlength = lentext(separator)
		var/list/textList   = new /list()
		var/searchPosition  = 1
		var/findPosition    = 1
		var/buggyText
		while (1)															// Loop forever.
			findPosition = findtext(text, separator, searchPosition, 0)
			buggyText = copytext(text, searchPosition, findPosition)		// Everything from searchPosition to findPosition goes into a list element.
			textList += "[buggyText]"										// Working around weird problem where "text" != "text" after this copytext().

			searchPosition = findPosition + separatorlength					// Skip over separator.
			if (findPosition == 0)											// Didn't find anything at end of string so stop here.
				return textList
			else
				if (searchPosition > textlength)							// Found separator at very end of string.
					textList += ""											// So add empty element.
					return textList
